// https://leetcode-cn.com/problems/task-scheduler/
// 621. Task Scheduler
function leastInterval(tasks: string[], n: number): number {
    const freq = tasks.reduce((prev, key) => {
	prev[key] === undefined ? prev[key] = 1 : prev[key]++;
	return prev;
    }, {});

    const nums = Object.values(freq) as number[];
    const maxExec = Math.max(...nums);
    const count = nums.filter(item => item === maxExec).length;
    return Math.max(tasks.length, (maxExec - 1) * (n + 1) + count);
}
